<?php
namespace app\index\model;

class Visit{
    //
    public static function instance(){
        return new Visit();
    }
    //
    public function log($log){
        $init = ['tname'=>'','ip'=>'','agent'=>'','url'=>'','referer'=>'','deny'=>0,'types'=>0,'city'=>'','isp'=>'','block'=>'','tpl'=>'','addtime'=>time()];
        $log = array_merge($init, $log);
        try{
            db('visit_log')->insert($log);
        }catch(\Exception $e){}
    }
    //
    public function sum($aid){
        if(!is_numeric($aid)){
            return 0;
        }
        $data = [];
        $data['aid'] = $aid;
        $data['xdate'] = date('Y-m-d');
        $table = db('visit_count');
        $vcid = $table->where($data)->value('vcid', 0);
        if(!$vcid){
            try{
                $vcid = $table->insertGetId($data);
            }catch(\Exception $e){
                return 0;
            }
        }
        return $vcid;
    }
}